package com.example.tome.module_base.base;


import com.example.tome.component_router.baseApp.BaseApplication;
import com.example.tome.component_router.dagger.component.ActivityComponent;
import com.example.tome.component_router.dagger.component.DaggerActivityComponent;
import com.example.tome.component_router.dagger.module.ActivityModule;

import javax.inject.Inject;

/**
 * @Created by TOME .
 * @时间 2018/5/2 17:40
 * @描述 ${MVP模式的Base Activity}
 */

public abstract class BaseMVPActivity<T extends AbstractPresenter> extends BaseCommonActivity implements IView{

    @Inject
    protected T mPresenter ;


    protected ActivityComponent getActivityComponent() {
        return DaggerActivityComponent.builder()
                .appComponent(BaseApplication.getAppComponent())
                .activityModule(new ActivityModule(this))
                .build();

    }

    @Override
    protected void onViewCreated() {
        super.onViewCreated();
        initInject();
        if (mPresenter != null) {
            mPresenter.attachView(this);
        }

    }

    @Override
    public void onSuccess() {

    }

    @Override
    public void showError(String msg, String code) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void showErrorMsg(String errorMsg) {

    }

    @Override
    protected void onDestroy() {
        if (mPresenter != null) {
            mPresenter.detachView();
        }
        super.onDestroy();
    }

    /**
     * 注入当前Activity所需的依赖
     */
    protected abstract void initInject();
}
